#!/usr/bin/python
myneighbors = []
myvid = ''
pid2vid = {}
vid2pid = {}
routingTable = {} 
rdvStore = {} 
myprintid = ''
L = 0
# Routing table is a dictionary, it contains the values at each distances from 1 to L
# So key in the routing table is the bucket distance, value is the 3 tuple: tuple 1 = nexthop (vid), tuple 2 = gateway (vid), tuple 3 = prefix (string)

# RDV STORE is a dictionary: it stores the list of edges with distances
# open the topo file
fin = open('topo/7.adlist','r')
# read the file line by line
line = fin.readline()
line = line.strip()
while line != '':
    if line.find(mypid) ==0:
        # this is the line which contains the neighbor list for my 
        myneighbors = (line.split(' '))[1:]
        break
    line = fin.readline()
    line = line.strip()
fin.close()

if ' ' in myneighbors:
    print 'Warning: My neighbor list contains empty pids!'
if  len(myneighbors) < 1:
    print 'Warning: My neighbor list is empty, will quit now!'
    sys.exit(0)
print 'Myneighbors: ',myneighbors 

fin = open('topo/7.vid', 'r')
line = fin.readline()
line = line.strip()
while line != '':
    tokens = line.split(' ')
    if tokens[0] in myneighbors:
        pid2vid[tokens[0]] = tokens[1]
        vid2pid[tokens[1]] = tokens[0] 
    elif tokens[0] == mypid:
        myvid = tokens[1] 
    
    line = fin.readline()
    line = line.strip()
fin.close()
print vid2pid